//
//  SleepDataModel.swift
//  TimeBoat
//
//  Created by Jun on 2022/9/8.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import Foundation


@objcMembers class SleepItem: NSObject {
    var hour: UInt8 = 0
    var minute: UInt8 = 0
    var state: UInt8 = 0
    
    init(hour: UInt8, minute: UInt8, state: UInt8) {
        super.init()
        
        self.hour = hour
        self.minute = minute
        self.state = state
    }
    
    @objc func toString() -> String {
        var str = self.yy_modelToJSONString()
        if nil == str {
            str = ""
        }
        
        return str!
    }
}

/// 睡眠
@objcMembers class SleepDataModel: NSObject {
    /// 数据列表
    var sleepDataList: [SleepItem] = [SleepItem]()
    
    convenience init(buf: [UInt8], dataLength: Int) {
        self.init()
        
        var data = [SleepItem]()

        if (buf.count >= dataLength) {
            let unit = 3
            let arrayCount = Int(dataLength / unit)


            var h: UInt8 = 0
            var m: UInt8 = 0
            var s: UInt8 = 0
            if arrayCount > 0 {
                for index in 0...(arrayCount-1) {
                    h = buf[index * unit]
                    m = buf[index * unit + 1]
                    s = buf[index * unit + 2]
                    data.append(SleepItem(hour: h, minute: m, state: s))
                }
            }
        }

        sleepDataList = data
    }
    
    @objc func toString() -> String {
        var str = self.yy_modelToJSONString()
        if nil == str {
            str = ""
        }
        
        return str!
    }
}
